package com.lam.generator.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lam.common.utils.CollectionUtil;
import com.lam.common.utils.StringUtils;
import com.lam.generator.common.config.GenConfig;
import com.lam.generator.entity.DbTable;
import com.lam.generator.entity.DbTableColumn;
import com.lam.generator.mapper.GenDbTableMapper;
import com.lam.generator.param.GenDbTableParam;
import com.lam.generator.service.GenDbTableService;

/**
 * 业务 服务层实现
 * 
 * @author lam
 */
@Service
public class GenDbTableServiceImpl implements GenDbTableService {
	
	@Autowired
	private GenDbTableMapper genDbTableMapper;
	
	/**
	 * 查询据库列表
	 * 
	 * @param genTable 业务信息
	 * @return 数据库表集合
	 */
	@Override
	public List<DbTable> selectTableList(GenDbTableParam param) {
		
		param.setFilterTablePrefixList(StringUtils.str2List(GenConfig.getTablePrefix()));
		return genDbTableMapper.selectTableList(param);
	}
	
	@Override
	public DbTable selectTableByName(String tableName) {
		
		GenDbTableParam param = new GenDbTableParam();
		param.setTableName(tableName);
		return CollectionUtil.getFirst(genDbTableMapper.selectTableList(param));
	}
	
	/**
	 * 根据表名称查询列信息
	 * @param tableName 表名称
	 * @return 列信息
	 */
	@Override
	public List<DbTableColumn> selectColumnListByTable(String tableName) {
		
		return genDbTableMapper.selectColumnListByTable(tableName);
	}
	

}